var e = require("../../utils/util.js"), time = require('../../utils/util.js');
import CONFIG from '../../config.js';
var app = getApp();
import {
  querySelfBusinessInfo
} from '../../api/personApply.js'
Page({
  data: {
    avatarUrl: "/images/bing.png",
    name: '',
    mobile: '',
    defaultAvatarUrl: "/images/main/default_avatar.png",
    defaultNickName: "用户名称",
    presentCount: 0,
    practiceday: '',
    studytime: '',
    personInfo: '',  //个体户信息
    noExistPersonInfo:false,
    version:app.globalData.version,
    practicetime: "",
    today_s: "",
    vip: false,
    StatusBar: app.globalData.StatusBar,
    CustomBar: app.globalData.CustomBar,
    ColorList: app.globalData.ColorList,
    active: 'user',
    icon: {
      normal: '/images/yh.png',
      active: '/images/yh1.png'
    }
  },
  onChange(event) {
    console.log(event)
  
    if (event.detail == 1) {
      wx.navigateTo({
        url: '../Invoice/Invoice'
      })
    }
    if (event.detail == 0) {
      wx.navigateTo({
        url: '../index/index'
      })
    }
    this.setData({ active: "user" });
  },
  onLoad: function (options) {
    console.log(wx.getStorageSync("mobile"))
    querySelfBusinessInfo().then(res => {
      if (res.sub_code != 'isp.unknown-error') {
        this.setData({
          personInfo: res
        })
      }
    }).catch(err => {
      Notify({
        type: 'danger',
        message: err
      })
    })
    this.setData({
      name: app.globalData.userInfo.nickName,
      mobile: app.globalData.userInfo.mobile || '',
      avatarUrl: app.globalData.userInfo.imageUrl
    })
  },

  onReady: function () {


  },
  //跳转到指定页面,带校验
  goToPageAndVal(event) {
    console.log(this.data.personInfo.status)
    if (this.data.personInfo.status < 20 || this.data.personInfo.status == undefined)
    {
      this.setData({
        noExistPersonInfo:true
      })
      
    }
    else
    {
      wx.navigateTo({
        url: event.currentTarget.dataset.url
      })
    }
    // this.onClickHide()
    // if (this.validate()) { //验证状态
    //   console.log("validate true")
    // }
      //执行跳转
     
    
  },
  goToPageAnd(event){
    wx.navigateTo({
      url: event.currentTarget.dataset.url
    })
  },

  onClickHide:function(){
    this.setData({
      noExistPersonInfo:false
    })
  },
 
  joinVip: function () { //加入VIP
    // wx.navigateTo({
    //   url: '../vip/vip',
    // })
  },
  chooseGeren: function () {
    // wx.navigateTo({
    //   url: '../form/form',
    // })
  },
 
  sign_in: function () {
    // wx.navigateTo({
    //   url: '../sign_in/sign_in',
    // })
  },
  onPullDownRefresh() {

  },
  onShow(){
    querySelfBusinessInfo().then(res => {
      if (res.sub_code != 'isp.unknown-error') {
        console.log(res)
        this.setData({
          personInfo: res
        })
      }
    }).catch(err => {
      Notify({
        type: 'danger',
        message: err
      })
    })
  },
  /**
   * 用户点击右上角分享
   */
  onShareAppMessage: function (res) {
    // if (res.from === 'button') {
    //   // 来自页面内转发按钮
    //   console.log(res.target)
    // }
    // return {
    //   title: '看看',
    //   path: 'pages/study/study',
    //   success: function (res) {
    //     // 转发成功
    //     wx.showShareMenu({
    //       // 要求小程序返回分享目标信息
    //       withShareTicket: true
    //     });
    //   },
    //   fail: function (res) {
    //     // 转发失败
    //   }
    // }
  }
})
